﻿@model USERS.CYT369.COM.Models.AccountView.RegisterViewModel
@{
    ViewBag.Title = "用户注册";
    ViewBag.HeaderName = "新用户注册";
    Layout = "_RegisterLoginLayout1";

}
@section scripts{
    <script type="text/javascript">
        function OnChangeRole(role) {
            if (role == 1) {
                $("#restaurantFirm").addClass("selected-role");
                $("#serviceFirm").removeClass("selected-role");
            } else if (role == 2) {
                $("#serviceFirm").addClass("selected-role");
                $("#restaurantFirm").removeClass("selected-role");
            }
            $("#UserType").val(role);
        }

        function GetCaptcha(btn) {
            if ($(btn).attr("disable") != "true") {
                var m = $("#UserName").val().trim();
                if (m.length < 1) {
                    $("#error_msg").text("手机号不能为空!");
                    $(".err-msg").show();
                } else {
                    $.post('@Url.Content("~/Account/GetRegisterCaptcha")?m=' + m + '&t=' + new Date().getTime(), function (e) {
                        if (e.Result) {
                            $("#CaptchaCode").attr("hascode", 1);
                            $(btn).attr("disable", true);
                            $(btn).attr("second", 60);
                            $(btn).text("重新获取(60)");
                            $(btn).addClass("captcha-btn-disable");
                            setTimeout("SecondChange()", 1000);
                        } else {
                            $("#error_msg").text(e.Msg);
                            $(".err-msg").show();
                        }
                    });
                }
            }
        }

        function SecondChange() {
            var btn = $("#captcha-btn");
            var second = parseInt(btn.attr("second"));
            if (second > 0) {
                second -= 1;
                btn.attr("second", second);
                btn.text("重新获取(" + second + ")");
                if (second > 0) {
                    setTimeout("SecondChange()", 1000);
                } else {
                    $(btn).attr("disable", false);
                    $(btn).removeClass("captcha-btn-disable");
                    btn.text("获取动态码");
                }
            }
        }

        function OnTextKeyDown(e) {
            if (event.keyCode == 13) {
                DoRegister();
            }
        }

        function DoRegister() {
            if ($("#licenseChk")[0].checked) {
                var user = {
                    UserName: $("#UserName").val().trim(),
                    Password: $("#Password").val().trim(),
                    CaptchaCode: $("#CaptchaCode").val().trim(),
                    PhoneNumber: $("#UserName").val().trim(),
                    UserType: $("#UserType").val().trim(),
                    ReturnUrl: $("#ReturnUrl").val().trim(),
                    ResultUrl: $("#ResultUrl").val().trim(),
                    AppID: $("#AppID").val().trim()
                };
                if (user.UserName.length < 1) {
                    $("#error_msg").text("登录用户名不能为空!");
                    $(".err-msg").show();
                    return;
                }
                if (user.Password.length < 1) {
                    $("#error_msg").text("密码不能为空。");
                    $(".err-msg").show();
                    return;
                }

                if ($("#CaptchaCode").attr("hascode") != "1") {
                    $("#error_msg").text("请先获取获取动态码。");
                    $(".err-msg").show();
                    return;
                }
                //
                if (user.CaptchaCode < 1) {
                    $("#error_msg").text("验证码不能为空。");
                    $(".err-msg").show();
                    return;
                }

                $("#submit").attr('disabled', 'disabled');
                $("#submit").addClass("submit-btn-disable");

                $.ajax({
                    url: '@Url.Content("~/Account/Register")',
                    type: "POST",
                    contentType: "application/json;charset=utf-8",
                    data: JSON.stringify(user),
                    success: function (e) {
                        if (e.Result) {
                            location.href = e.Msg;
                        } else {
                            $("#error_msg").text(e.Msg);
                            $(".err-msg").show();

                            $("#submit").removeAttr('disabled');
                            $("#submit").removeClass("submit-btn-disable");
                        }
                    },
                    error: function () {
                        $("#submit").removeAttr('disabled');
                        $("#submit").removeClass("submit-btn-disable");
                    }
                });
            } else {
                $("#error_msg").text("确认已阅读并同意本站服务协议和个人信息保护政策");
                $(".err-msg").show();
            }
        }
    </script>
}
<div class="page-bg" style="position:relative">
    <img class="bg" src="~/css/images/register-bg2.jpg" />
    <div class="form-panel">
        <div class="panel-name">用户注册</div>
        <div class="err-msg"><i class="fa fa-info-circle"></i><span id="error_msg"></span></div>
        <form class="form" method="post" action="~/Account/Register" autocomplete="off">
            <div class="row">
                <input class="input iphone-input" id="UserName" name="UserName" type="text" placeholder="请输入常用的手机号" maxlength="11" autocomplete="off" style="width:220px" />
                <div class="input-icon icon-iphone"></div>
            </div>
            <div class="row">
                <input class="input" name="CaptchaCode" id="CaptchaCode" type="text" placeholder="输入6位动态码" autocomplete="off" maxlength="6" style="width:125px" />
                <div class="input-icon icon-captcha"></div>
                <div class="captcha-btn" id="captcha-btn" onclick="GetCaptcha(this)">获取动态码</div>
            </div>
            <div class="row">
                <input class="input" name="Password" id="Password" type="password" placeholder="密码(6-16位字母/数字/符号)" autocomplete="off" maxlength="16" style="width:220px" onkeydown="OnTextKeyDown()" />
                <div class="input-icon icon-password"></div>
            </div>
            <div class="row" style="display:flex;justify-content:space-between">
                <input name="UserType" id="UserType" type="hidden" value="0" />
                <div id="restaurantFirm" class="role" onclick="OnChangeRole(1)">
                    <div class="icon">
                        <i class="fa fa-user-circle" style="color:#f592b6"></i>
                    </div>
                    <div class="info-text">
                        <div class="user-type">我是餐饮企业</div>
                        <div>我需要找供应商</div>
                    </div>
                </div>
                <div id="serviceFirm" class="role" onclick="OnChangeRole(2)">
                    <div class="icon">
                        <i class="fa fa-user-circle" style="color:#abcbf9"></i>
                    </div>
                    <div class="info-text">
                        <div class="user-type">我是供应商</div>
                        <div>我有产品和服务</div>
                    </div>
                </div>
            </div>
            <div class="row" style="border-top:dotted 1px orange;margin-top:10px;">
                <div class="license-info">
                    <input id="licenseChk" type="checkbox" value="1" />
                    <label for="licenseChk">
                        我已阅读并同意 <b><a target="_blank" href="~/Rules/RuleView/eyJSdWxlSUQiOjJ9">服务协议</a></b>、
                        <b><a target="_blank" href="~/Rules/RuleView/eyJSdWxlSUQiOjF9">个人信息保护政策</a></b>
                    </label>
                </div>
                <input name="ReturnUrl" id="ReturnUrl" type="hidden" value="@ViewBag.ReturnUrl" />
                <input name="ResultUrl" id="ResultUrl" type="hidden" value="@ViewBag.ResultUrl" />
                <input name="AppID" id="AppID" type="hidden" value="@ViewBag.AppID" />
                <input name="submit" id="submit" class="submit-btn" type="button" value="注  册" onclick="DoRegister()" />
            </div>
        </form>
        <div class="panel-expand">
            <span>我已有账号，</span>
            <a class="a" href="/Account/Login?appid=@ViewBag.AppID&returnUrl=@ViewBag.ReturnUrl&resultUrl=@ViewBag.ResultUrl">立即登录&nbsp;&gt;&gt;</a>
        </div>
    </div>

</div>
